home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Application that fills a large chunk of memory and then sees if that
- ** memory gets overwritten. This is a simple debugging tool.
- **
- ** by Mark Cookson, Apple Developer Technical Support
- **
- ** File: Fill Memory.h
- **
- ** Copyright ©1996 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "Apple Sample
- ** Code" after having made changes. If you're going to re-distribute the
- ** source, we require that you make it clear in the source that the code
- ** was descended from Apple Sample Code, but that you've made changes.
- */
-
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <TextEdit.h>
- #include <Windows.h>
-
- static void ToolBoxInit (void) {
- MaxApplZone();
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs ((long)nil);
- InitCursor ();
- return;
- }
-
- void main (void) {
- EventRecord anEvent;
- unsigned long * theBuffer = nil,
- spaceWanted = 0,
- i = 0;
- Size freeMem = 0,
- growSize = 0;
-
- ToolBoxInit ();
- freeMem = MaxMem (&growSize);
- spaceWanted = (freeMem - 1024) & ~3;
- // save a K so the process manager can switch out of our app
- // the & ~3 makes the memory allocated an integer number of longs (for speed)
- theBuffer = (unsigned long *)NewPtr (spaceWanted);
- if (!theBuffer || MemError ()) {
- DebugStr ("\pCouldn't get memory"); // Where did the memory go?
- return;
- }
-
- for (i = 0; i < spaceWanted / 4; i++) // Fill memory with our pattern
- ((unsigned long *)theBuffer)[i] = 0xA5A5A5A5;
-
- while (anEvent.what != keyDown) {
- WaitNextEvent (keyDownMask, &anEvent, 6, nil);
- for (i = 0; i < spaceWanted / 4; i++) {
- if (((unsigned long *)theBuffer)[i] != 0xA5A5A5A5)
- DebugStr ("\pFill Memory memory's got trashed!");
- }
- }
- }